RFC: Use `np.int64` by default for CSR matrices' `indices` and `indptr` · Issue #16774 · scipy/scipy · GitHub

您所在的位置:网站首页 scipy sparse matrices RFC: Use `np.int64` by default for CSR matrices' `indices` and `indptr` · Issue #16774 · scipy/scipy · GitHub

RFC: Use `np.int64` by default for CSR matrices' `indices` and `indptr` · Issue #16774 · scipy/scipy · GitHub

2023-04-02 00:41| 来源: 网络整理| 查看: 265

Context

When creating a scipy.sparse.csr_matrix (for instance using a numpy array), the underlying indices and indptr arrays either use np.int32 or np.int64 depending on nnz, the number of non zeros elements (namely int64 are used when nnz >= 2**31):

scipy/scipy/sparse/_sputils.py

Lines 134 to 185 in 935d537

def get_index_dtype(arrays=(), maxval=None, check_contents=False): """ Based on input (integer) arrays `a`, determine a suitable index data type that can hold the data in the arrays. Parameters ---------- arrays : tuple of array_like Input arrays whose types/contents to check maxval : float, optional Maximum value needed check_contents : bool, optional Whether to check the values in the arrays and not just their types. Default: False (check only the types) Returns ------- dtype : dtype Suitable index data type (int32 or int64) """ int32min = np.int32(np.iinfo(np.int32).min) int32max = np.int32(np.iinfo(np.int32).max) dtype = np.intc if maxval is not None: maxval = np.int64(maxval) if maxval > int32max: dtype = np.int64 if isinstance(arrays, np.ndarray): arrays = (arrays,) for arr in arrays: arr = np.asarray(arr) if not np.can_cast(arr.dtype, np.int32): if check_contents: if arr.size == 0: # a bigger type not needed continue elif np.issubdtype(arr.dtype, np.integer): maxval = arr.max() minval = arr.min() if minval >= int32min and maxval


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3